/**
 * @file bsp_aht21_reg.h
 * @author liufeng (liufeng@injoinic.com)
 * @brief AHT21 driver header file.
 * @version 0.1
 * @date 2024-10-28
 *
 * @copyright Copyright (c) 2024  injoinic
 *
 */

/* Inlcude ------------------------------------------------------------------ */

#include "bsp_aht21_reg.h"
#include "stdint.h"

/* Define ------------------------------------------------------------------- */

// 1.aht21 driver函数返回值枚举
typedef enum
{
    AHT21_OK,             // aht21 operation  successfully
    AHT21_NEED_CALIBRATE, // aht21 need calibrate
    AHT21_BUSY,           // aht21 is busy, don't use the data
    AHT21_CRC_FAIL,       // aht21 crc check fail
} aht21_func_ret;

// 2.aht21 driver需要的所有外部函数接口定义
typedef struct
{
    /* iic相关函数的接口 */
    void (*pf_iic_init)(void);   // iic init interface
    void (*pf_iic_deinit)(void); // iic deinit interface
    uint8_t (*pf_iic_write_bytes)(uint8_t addr, uint8_t* buff, uint8_t len); // iic write
    uint8_t (*pf_iic_read_bytes)(uint8_t addr, uint8_t* buff, uint8_t len);  // iic read

    /* 关中断或者进入临界区的函数接口 */
    void (*pf_disable_irq)(void); // disable irq(without OS) or enter critical(with OS)
    void (*pf_enable_irq)(void);  // enable irq(without OS) or exit critical(with OS)

    /* 时基相关的函数接口 */
    void (*pf_delay_ms)(uint32_t); // blocking delay(without OS) or unblocking delay(with OS)
} aht21_driver_input_func;

// 3.aht21 driver结构体定义
typedef struct aht21_type_tag aht21_type;
struct aht21_type_tag
{
    /* 外部函数指针 */
    aht21_driver_input_func* func_port; // all outside function port

    /* Export Functions */
    uint8_t (*pf_aht21_init)(aht21_type* aht21_instance);           // AHT21 init
    uint8_t (*pf_aht21_deinit)(aht21_type* aht21_instance);         // AHT21 deinit
    uint8_t (*pf_aht21_getTempAndHumi)(aht21_type* aht21_instance); // get AHT21 temp and humi

    /* Export Variables */
    float temprature; // temprature of result
    float humidity;   // humidity of result
};

/* Declaration -------------------------------------------------------------- */

uint8_t aht21_construct(aht21_type* aht21_instance, aht21_driver_input_func* input_arg);
